package com.link2room.rodimus.nmsrunner;

import com.aliyun.mns.model.Message;
import com.link2room.common.mns.Worker;
import com.link2room.common.util.ExceptionUtil;
import com.link2room.common.util.JacksonUtil;
import com.link2room.common.util.LogUtil;
import com.link2room.rodimus.dto.param.base.SignDistributeAwardParamDto;
import com.link2room.rodimus.facade.ISignInAwardHandler;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by LN on 2018/1/8
 */
@Component("signInDistributeAwardWorker")
public class SignInDistributeAwardWorker implements Worker {
    @Resource
    private ISignInAwardHandler signInAwardHandler;
    @Override
    public boolean exec(Message message) throws Exception {
        Integer count = message.getDequeueCount();
        if(count > 1){
            return true;
        }else {
            SignDistributeAwardParamDto paramDto = JacksonUtil.jsonToBean(message.getMessageBody(),SignDistributeAwardParamDto.class);
            try {
                signInAwardHandler.distributeAward(paramDto);
                return true;
            }catch (Exception e){
                ExceptionUtil.getExceptionDetail(e);
                return false;
            }
        }
    }
}
